package com.songshuai.webapi.permission.common.enumerations;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum ContactTool {
    Mobile(1000100, "手机"),
    MobileOverSea(1000101, "海外手机"),
    Line(1000102, "直线"),
    Email(1000103, "邮箱"),
    QQ(1000104, "QQ"),
    Wechat(1000105, "微信"),
    NetPhone(1000106, "网络电话"),
    Telephone(1000107, "座机"),
    WeUnionId(1000108, "微信UnionId");
    private int code;
    private String msg;

    ContactTool(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return ContactTool.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return 0;
        }
    }

    public static String getMsg(String define){
        try {
            return ContactTool.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return "";
        }
    }

    public static String getMsg(int code){
        for(ContactTool err : ContactTool.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "errorCode not defined ";
    }

    public int getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }
}
